package com.chang.annoValidation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
import org.springframework.validation.Validator;

@Service
public class MyValidationTwo {
    @Autowired
    private Validator validator;

    public boolean ValidationTest(User user) {
        BindException bindException = new BindException(user, user.getName());
        validator.validate(user, bindException);
        System.out.println(bindException);
        return bindException.hasErrors(); // 判断是否有异常
    }
}
